package com.example.wblog.dao;

import com.example.wblog.model.Article;
import com.example.wblog.model.LoginTicket;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleDAO {
    String TABLE_NAME = " article ";
    String INSERT_FIELD = " title, describes, content, created_date, comment_count, category ";
    String SELECT_FIELD = " id, " + INSERT_FIELD;

    @Insert({"insert into", TABLE_NAME, "(", INSERT_FIELD, ") values (#{title}, #{describes}, #{content}, #{createdDate}, #{commentCount}, #{category})"})
    int add(Article article);

    @Select({"select", SELECT_FIELD, "from", TABLE_NAME, "order by id desc limit #{offset}, #{size}"})
    List<Article> selectList(int offset, int size);

    @Select({"select", SELECT_FIELD, "from", TABLE_NAME, "where id = #{id}"})
    Article selectById(int id);

    @Delete({"delete from", TABLE_NAME, "where id = #{id}"})
    void deleteById(int id);

}
